package com.qf.service.impl;

import com.qf.mapper.AdminMapper;
import com.qf.pojo.Admin;
import com.qf.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    /**
     * 登录
     * @param username
     * @param password
     * @return
     */
    @Override
    public Admin login(String username, String password) {
        Admin admin = adminMapper.findByUsername(username);
        if (admin != null){
            if (admin.getPassword().equals(password)) {
                return admin;
            }else {
                throw new RuntimeException("账号或密码错误,请重新输入");

            }
        }else {
            throw new RuntimeException("账号不存在,请重新输入");
        }
    }

    /**
     * 修改密码
     * @param admin
     * @return
     */
    @Override
    public void updatePassword(Admin admin) {
        adminMapper.updateByUsername(admin);
    }
}
